//
//  SAPaperSetVC.m
//  saasRetail
//
//  Created by 黄志刚 on 2022/5/12.
//

#import "SAPaperSetVC.h"
#import "SAPaperSetTableViewCell.h"
#import "SAPaperSetModel.h"
#import "SACommoditySpecialFeesModel.h"
#import "SAPaperSetFootView.h"
#import "SAPaperSetCollectionViewCell.h"
#import "BubbleTableView.h"
#import "SAPaperSetCollectionFootView.h"
#import "ZXingObjC.h"

@interface SAPaperSetVC ()<UITableViewDelegate,UITableViewDataSource,UICollectionViewDataSource,UICollectionViewDelegate>

@property (nonatomic, strong) UIButton *confirmBtn;
@property (nonatomic, strong) UIView *contentView;
@property (nonatomic, strong) UIButton *lableSetBtn;
@property (nonatomic, strong) UIButton *paperSetBtn;
@property (nonatomic, strong) UIButton *fiftyEightBtn;
@property (nonatomic, strong) UIButton *eightyBtn;
@property (nonatomic, strong) UIButton *littleBtn;
@property (nonatomic, strong) UIButton *bigBtn;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray<SAPaperSetModel *> *dataMarr;//显示时候使用
@property (nonatomic, strong) NSMutableArray<SAPaperSetModel *> *dataMarr2;//上传数据时候使用
@property (nonatomic, strong) NSMutableArray<SAPaperSetModel *> *laberMarr;//标签数据
@property (nonatomic, strong) UIView *lableView;
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) NSDictionary *dic;
@property (nonatomic, strong) UILongPressGestureRecognizer *longPress;
@property (nonatomic, strong) BubbleTableView *typeBubbleView;
@property (nonatomic, strong) UIImageView *imageV;
@property (nonatomic, strong) NSMutableArray *typeMarr;
@property (nonatomic, assign) NSInteger typeRow;
@property (nonatomic, strong) UILabel *sizeLab;
@property (nonatomic, strong) UIView *previewView;
@property (nonatomic, strong) UIImageView *barcodeImageV;
@property (nonatomic, strong) UIView *previewView2;

@property (nonatomic, strong) UILabel *modelPhoneLab;
@property (nonatomic, strong) UILabel *modelMembersLab;
@property (nonatomic, strong) UILabel *modelAvailableIntegralLab;
@property (nonatomic, strong) UILabel *modelCurrentIntegralLab;
@property (nonatomic, strong) UIView *productView;
@property (nonatomic, strong) UIView *productView2;
@property (nonatomic, strong) UILabel *modelSalesLab;
@property (nonatomic, strong) UILabel *modelReturnTipLab;
@property (nonatomic, strong) UILabel *modelWholeDiscountLab;
@property (nonatomic, strong) UILabel *modelDiscountPriceLab;
@property (nonatomic, strong) UILabel *modelCardPriceLab;
@property (nonatomic, strong) UILabel *modelReceivableLab;
@property (nonatomic, strong) UILabel *modelPaidinLab;
@property (nonatomic, strong) UILabel *modelBalanceLab;
@property (nonatomic, strong) UILabel *modelPayTypeLab;
@property (nonatomic, strong) UILabel *modelOperationLab;
@property (nonatomic, strong) UILabel *modelContactPhoneLab;
@property (nonatomic, strong) UILabel *modelContactAddressLab;
@property (nonatomic, strong) UILabel *modelTipLab;
@property (nonatomic, strong) UIImageView *codeImageV;
@property (nonatomic, strong) UILabel *modelInformationPlatformLab;
@property (nonatomic, strong) UILabel *modelInformationPlatformLab2;
@property (nonatomic, strong) UILabel *modelInformationPlatformLab3;
@property (nonatomic, strong) UIView *styleView;
@property (nonatomic, strong) UIScrollView *styleView2;
@property (nonatomic, strong) SAPaperSetModel *hkongModel;

@property (nonatomic, strong) UILabel *modePriceLab;
@property (nonatomic, strong) UILabel *modediscountPriceLab;
@property (nonatomic, strong) UILabel *specialPriceLab;

@property (nonatomic, strong) UILabel *vipPriceLab;
@property (nonatomic, strong) UILabel *groupLab;
@property (nonatomic, strong) UILabel *dealerLab;

@end

@implementation SAPaperSetVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

-(void)initData {
    //组合数据
    NSArray *arr = @[@"会员", @"手机", @"可用积分", @"本次积分", @"折扣", @"整单折扣", @"抵扣金额", @"卡劵金额", @"退货标识", @"结算方式", @"可用余额", @"操作人", @"联系电话", @"联系地址", @"提醒", @"店铺二维码", @"平台信息", @"原总价"];
    
    NSArray *arr2 = @[@"0",@"1",@"2",@"3",@"16",@"4",@"5",@"14",@"6",@"7",@"8",
                     @"9",@"10",@"11",@"12",@"13",@"15",@"17"];
    
    SACommoditySpecialFeesModel *ticketLayoutAttribute = [SAOverallSetting shareInstance].ticketLayoutAttribute;
    NSArray *arr3 = [ticketLayoutAttribute.value componentsSeparatedByString:@","];
    if (arr3.count < 18) {
        arr3 = [NSArray arrayWithObjects:@"0", @"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12",@"13",@"14",@"15",@"16",@"17",nil];
    }
    [self.dataMarr2 removeAllObjects];
    for (NSString *str in arr3) {
        if ([str integerValue] < 18) {
            SAPaperSetModel *model = [SAPaperSetModel new];
            model.valueStr = str;
            [self.dataMarr2 addObject:model];
        }
    }
    [self.dataMarr removeAllObjects];
    for (int i = 0; i < arr2.count; i++) {
        NSInteger index = [arr2[i] intValue];
        NSString *str = arr[i];
        NSString *value = self.dataMarr2[index].valueStr;
        self.dataMarr2[index].titleStr = str;
        if ([value isEqualToString:@"-0"]) {
            self.dataMarr2[index].isSelect = NO;
        }else {
            self.dataMarr2[index].isSelect = ([value integerValue] >= 0);
        }
        [self.dataMarr addObject:self.dataMarr2[index]];
    }
    
    SACommoditySpecialFeesModel *hkSymbol = [SAOverallSetting shareInstance].hkSymbol;
    SAPaperSetModel *hkongModel = [SAPaperSetModel new];
    hkongModel.isSelect = [hkSymbol.value isEqualToString:@"1"];
    self.hkongModel = hkongModel;
   
    [self.tableView reloadData];
    if ([[SAOverallSetting shareInstance].printSize.value isEqualToString:@"0"]) {
        self.fiftyEightBtn.selected = YES;
        self.eightyBtn.selected = NO;
    }else {
        self.fiftyEightBtn.selected = NO;
        self.eightyBtn.selected = YES;
    }
    
    if ([[SAOverallSetting shareInstance].ticketFontSize.value isEqualToString:@"0"]) {
        self.littleBtn.selected = YES;
        self.bigBtn.selected = NO;
    }else {
        self.littleBtn.selected = NO;
        self.bigBtn.selected = YES;
    }
    
    SACommoditySpecialFeesModel *labelLayout = [SAOverallSetting shareInstance].labelLayout;
    self.typeRow = [labelLayout.value integerValue];
    [self refreshCollection:labelLayout.value];
}

-(void)refreshCollection:(NSString *)type {
    SACommoditySpecialFeesModel *labelLayoutAttribute = [SAOverallSetting shareInstance].labelLayoutAttribute;
    SACommoditySpecialFeesModel *sizeValue = [SAOverallSetting shareInstance].sizeValue4060;
    if ([type isEqualToString:@"1"]) {
        labelLayoutAttribute = [SAOverallSetting shareInstance].labelLayoutAttribute4060;
        sizeValue = [SAOverallSetting shareInstance].sizeValue4060;
        self.sizeLab.text = @"40*60mm";
    }else if ([type isEqualToString:@"2"]){
        labelLayoutAttribute = [SAOverallSetting shareInstance].labelLayoutAttribute4080;
        sizeValue = [SAOverallSetting shareInstance].sizeValue4080;
        self.sizeLab.text = @"40*80mm";
    }else if ([type isEqualToString:@"3"]){
        labelLayoutAttribute = [SAOverallSetting shareInstance].labelLayoutAttribute3020;
        sizeValue = [SAOverallSetting shareInstance].sizeValue3020;
        self.sizeLab.text = @"30*20mm";
    }else if ([type isEqualToString:@"4"]) {
        labelLayoutAttribute = [SAOverallSetting shareInstance].labelLayoutAttribute6040;
        sizeValue = [SAOverallSetting shareInstance].sizeValue6040;
        self.sizeLab.text = @"60*40mm";
    }else{
        labelLayoutAttribute = [SAOverallSetting shareInstance].labelLayoutAttribute4030;
        sizeValue = [SAOverallSetting shareInstance].sizeValue4030;
        self.sizeLab.text = @"40*30mm";
    }
    
    [self.laberMarr removeAllObjects];
    NSArray *arr = [labelLayoutAttribute.value componentsSeparatedByString:@","];
//    BOOL special = NO;
    for (NSString *str in arr) {
        SAPaperSetModel *model = [SAPaperSetModel new];
        model.valueStr = str;
        if ([model.valueStr isEqualToString:@"-0"]) {
            model.isSelect = NO;
        }else {
            model.isSelect = ([model.valueStr integerValue] >= 0);
        }
        NSString *key = [NSString stringWithFormat:@"%d",abs([str intValue])];
        model.fontStr = [NSString stringWithFormat:@"-%@",key];
        NSArray *fontArr = [sizeValue.value componentsSeparatedByString:@","];
        for (NSString *font in fontArr) {
            NSString *littleFont = [NSString stringWithFormat:@"-%@",key];
            NSString *bigFont = [NSString stringWithFormat:@"+%@",key];
            if ([font isEqualToString:littleFont] || [font isEqualToString:bigFont]) {
                model.fontStr = font;
            }
        }
        
        model.titleStr = self.dic[key];
        [self.laberMarr addObject:model];
    }
    [self.collectionView reloadData];
}

#pragma mark - UITableView Delegate & DataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataMarr.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    SAPaperSetTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SAPaperSetTableViewCell"];
    cell.model = self.dataMarr[indexPath.section];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return kScaleNum(46);
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [[UIView alloc] initWithFrame:CGRectZero];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.01;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    if (self.dataMarr.count == section + 1) {
        WeakSelf
        SAPaperSetFootView *footView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"SAPaperSetFootView"];
        footView.model = self.hkongModel;
        footView.previewBlock = ^{
            [weakSelf clickedPreview];
        };
        footView.HKBlock = ^{
            [weakSelf clickedShowHK];
        };
        return footView;
    }
    return [[UIView alloc] initWithFrame:CGRectZero];
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    if (self.dataMarr.count == section + 1) {
        return kScaleNum(154);
    }
    return 0.01;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
 
}

#pragma mark - UICollectionViewDataSource
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.laberMarr.count;
}

-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    WeakSelf
    static NSString *identifier = @"SAPaperSetCollectionViewCell";
    SAPaperSetCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
    SAPaperSetModel *model = self.laberMarr[indexPath.row];
    cell.model = model;
    cell.selectBlock = ^{
        [weakSelf isSelectModel:model];
    };
    return cell;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
}

- (void)collectionView:(UICollectionView *)collectionView moveItemAtIndexPath:(nonnull NSIndexPath *)sourceIndexPath toIndexPath:(nonnull NSIndexPath *)destinationIndexPath
{
    if (destinationIndexPath.row == 0) {
        [Prompt popPromptViewWithMsg:@"店铺名称必须排在首位" duration:2];
        [self.collectionView reloadData];
    }else if (destinationIndexPath.row == self.laberMarr.count - 1) {
        [Prompt popPromptViewWithMsg:@"条码必须排在末位" duration:2];
        [self.collectionView reloadData];
    }else {
        SAPaperSetModel *model = self.laberMarr[sourceIndexPath.row];
        [self.laberMarr removeObject:model];
        [self.laberMarr insertObject:model atIndex:destinationIndexPath.row];
        [self.collectionView reloadData];
    }
}

-(BOOL)collectionView:(UICollectionView *)collectionView canMoveItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
    if (indexPath.row == 0 || indexPath.row == self.laberMarr.count - 1) {
        return NO;
    }
    return YES;
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
    //返回段头段尾视图
    __weak typeof(self) weakSelf = self;
    //如果底部视图
    if (kind == UICollectionElementKindSectionFooter) {
        SAPaperSetCollectionFootView *footerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"SAPaperSetCollectionFootView" forIndexPath:indexPath];
        footerView.previewBlock = ^{
            [weakSelf clickedPreview2];
        };
        return footerView;
        
    }
    return nil;
}


#pragma mark - event
-(void)clickedLableSetBtn:(UIButton *)sender {
    if (sender.selected == YES) {
        return;
    }
    _lableSetBtn.selected = YES;
    _paperSetBtn.selected = NO;
    _lableSetBtn.backgroundColor = kBuleColor;
    _paperSetBtn.backgroundColor = [UIColor whiteColor];
    self.lableView.hidden = NO;
}

-(void)clickedPaperSetBtn:(UIButton *)sender {
    if (sender.selected == YES) {
        return;
    }
    _lableSetBtn.selected = NO;
    _paperSetBtn.selected = YES;
    _lableSetBtn.backgroundColor = [UIColor whiteColor];
    _paperSetBtn.backgroundColor = kBuleColor;
    self.lableView.hidden = YES;
}

-(void)clickedConfirmBtn {
    if (self.lableSetBtn.isSelected == YES) {
        NSMutableArray *valueMarr = [NSMutableArray array];
        NSMutableArray *fontMarr = [NSMutableArray array];
        for (int i = 0; i < self.laberMarr.count; i++) {
            NSString *str = [NSString stringWithFormat:@"%d",abs([self.laberMarr[i].valueStr intValue])];
            if (self.laberMarr[i].isSelect != YES) {
                str = [NSString stringWithFormat:@"-%d",abs([self.laberMarr[i].valueStr intValue])];
            }
            [valueMarr addObject:str];
            [fontMarr addObject:self.laberMarr[i].fontStr];
        }
        
        //清空标签，调试使用
//        valueMarr = [NSMutableArray arrayWithObjects:@"-0", @"-1",@"-2",@"-3",@"-4",@"-5",@"-6",@"-7",@"-8",@"-9",@"-10",@"-11",@"-12",nil];
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        NSMutableDictionary *dict2 = [NSMutableDictionary dictionary];
        if (self.typeRow == 1) {
            [dict setValue:[SAOverallSetting shareInstance].labelLayoutAttribute4060.settingsId forKey:@"settingsId"];
            [dict setValue:[SAOverallSetting shareInstance].labelLayoutAttribute4060.parentId forKey:@"parentId"];
            [dict2 setValue:[SAOverallSetting shareInstance].sizeValue4060.settingsId forKey:@"settingsId"];
            [dict2 setValue:[SAOverallSetting shareInstance].sizeValue4060.parentId forKey:@"parentId"];
        }else if (self.typeRow == 2) {
            [dict setValue:[SAOverallSetting shareInstance].labelLayoutAttribute4080.settingsId forKey:@"settingsId"];
            [dict setValue:[SAOverallSetting shareInstance].labelLayoutAttribute4080.parentId forKey:@"parentId"];
            [dict2 setValue:[SAOverallSetting shareInstance].sizeValue4080.settingsId forKey:@"settingsId"];
            [dict2 setValue:[SAOverallSetting shareInstance].sizeValue4080.parentId forKey:@"parentId"];
        }else if (self.typeRow == 3) {
            [dict setValue:[SAOverallSetting shareInstance].labelLayoutAttribute3020.settingsId forKey:@"settingsId"];
            [dict setValue:[SAOverallSetting shareInstance].labelLayoutAttribute3020.parentId forKey:@"parentId"];
            [dict2 setValue:[SAOverallSetting shareInstance].sizeValue3020.settingsId forKey:@"settingsId"];
            [dict2 setValue:[SAOverallSetting shareInstance].sizeValue3020.parentId forKey:@"parentId"];
        }else if (self.typeRow == 4) {
            [dict setValue:[SAOverallSetting shareInstance].labelLayoutAttribute6040.settingsId forKey:@"settingsId"];
            [dict setValue:[SAOverallSetting shareInstance].labelLayoutAttribute6040.parentId forKey:@"parentId"];
            [dict2 setValue:[SAOverallSetting shareInstance].sizeValue6040.settingsId forKey:@"settingsId"];
            [dict2 setValue:[SAOverallSetting shareInstance].sizeValue6040.parentId forKey:@"parentId"];
        }else {
            [dict setValue:[SAOverallSetting shareInstance].labelLayoutAttribute4030.settingsId forKey:@"settingsId"];
            [dict setValue:[SAOverallSetting shareInstance].labelLayoutAttribute4030.parentId forKey:@"parentId"];
            [dict2 setValue:[SAOverallSetting shareInstance].sizeValue4030.settingsId forKey:@"settingsId"];
            [dict2 setValue:[SAOverallSetting shareInstance].sizeValue4030.parentId forKey:@"parentId"];
        }
        [dict setValue:[valueMarr componentsJoinedByString:@","] forKey:@"value"];
        [dict2 setValue:[fontMarr componentsJoinedByString:@","] forKey:@"value"];
        [SANetManager requestWithType:(SkyHttpRequestTypePost) urlString:SA_BASE_URL(@"/system/settings/check") parameters:dict successBlock:^(id responseObject) {
            if (self.typeRow == 1) {
                [SAOverallSetting shareInstance].labelLayoutAttribute4060.value = [valueMarr componentsJoinedByString:@","];
            }else if (self.typeRow == 2) {
                [SAOverallSetting shareInstance].labelLayoutAttribute4080.value = [valueMarr componentsJoinedByString:@","];
            }else if (self.typeRow == 3) {
                [SAOverallSetting shareInstance].labelLayoutAttribute3020.value = [valueMarr componentsJoinedByString:@","];
            }else if (self.typeRow == 4) {
                [SAOverallSetting shareInstance].labelLayoutAttribute6040.value = [valueMarr componentsJoinedByString:@","];
            }else {
                [SAOverallSetting shareInstance].labelLayoutAttribute4030.value = [valueMarr componentsJoinedByString:@","];
            }
            [SANetManager requestWithType:(SkyHttpRequestTypePost) urlString:SA_BASE_URL(@"/system/settings/check") parameters:dict2 successBlock:^(id responseObject) {
                if (self.typeRow == 1) {
                    [SAOverallSetting shareInstance].sizeValue4060.value = [fontMarr componentsJoinedByString:@","];
                }else if (self.typeRow == 2) {
                    [SAOverallSetting shareInstance].sizeValue4080.value = [fontMarr componentsJoinedByString:@","];
                }else if (self.typeRow == 3) {
                    [SAOverallSetting shareInstance].sizeValue3020.value = [fontMarr componentsJoinedByString:@","];
                }else if (self.typeRow == 4) {
                    [SAOverallSetting shareInstance].sizeValue6040.value = [fontMarr componentsJoinedByString:@","];
                }else {
                    [SAOverallSetting shareInstance].sizeValue4030.value = [fontMarr componentsJoinedByString:@","];
                }
                [Prompt popPromptViewWithMsg:@"标签排版保存成功" duration:2];
                [self.navigationController popViewControllerAnimated:YES];
            } failureBlock:^(NSString *error) {
                [Prompt popPromptViewWithMsg:error duration:2];
            }];
        } failureBlock:^(NSString *error) {
            [Prompt popPromptViewWithMsg:error duration:2];
        }];
    }else {
        NSMutableArray *valueMarr = [NSMutableArray array];
        for (int i = 0; i < self.dataMarr2.count; i++) {
            NSString *str = [NSString stringWithFormat:@"%d",abs([self.dataMarr2[i].valueStr intValue])];
            if (self.dataMarr2[i].isSelect != YES) {
                str = [NSString stringWithFormat:@"-%d",abs([self.dataMarr2[i].valueStr intValue])];
            }
            [valueMarr addObject:str];
        }
        NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
        [parameters setValue:[SAOverallSetting shareInstance].ticketLayoutAttribute.settingsId forKey:@"settingsId"];
        [parameters setValue:[SAOverallSetting shareInstance].ticketLayoutAttribute.parentId forKey:@"parentId"];
        [parameters setValue:[valueMarr componentsJoinedByString:@","] forKey:@"value"];

        [SANetManager requestWithType:(SkyHttpRequestTypePost) urlString:SA_BASE_URL(@"/system/settings/check") parameters:parameters successBlock:^(id responseObject) {
            [SAOverallSetting shareInstance].ticketLayoutAttribute.value = parameters[@"value"];
            [Prompt popPromptViewWithMsg:@"小票模板保存成功" duration:2];
            [self.navigationController popViewControllerAnimated:YES];
        } failureBlock:^(NSString *error) {
            [Prompt popPromptViewWithMsg:error duration:2];
        }];
    }
}

-(void)clickedSelectBtn:(UIButton *)sender {
    if (sender == self.fiftyEightBtn) {
        self.fiftyEightBtn.selected = YES;
        self.eightyBtn.selected = NO;
    }else {
        self.fiftyEightBtn.selected = NO;
        self.eightyBtn.selected = YES;
    }
    
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:[SAOverallSetting shareInstance].printSize.settingsId forKey:@"settingsId"];
    [dict setValue:[SAOverallSetting shareInstance].printSize.parentId forKey:@"parentId"];
    if (self.fiftyEightBtn.selected == YES) {
        [dict setValue:@"0" forKey:@"value"];
    }else {
        [dict setValue:@"1" forKey:@"value"];
    }
    [SANetManager requestWithType:(SkyHttpRequestTypePost) urlString:SA_BASE_URL(@"/system/settings/check") parameters:dict successBlock:^(id responseObject) {
        [SAOverallSetting shareInstance].printSize.value = dict[@"value"];
    } failureBlock:^(NSString *error) {
        [Prompt popPromptViewWithMsg:error duration:2];
    }];
}

-(void)clickedSelectFontBtn:(UIButton *)sender {
    if (sender == self.littleBtn) {
        self.littleBtn.selected = YES;
        self.bigBtn.selected = NO;
    }else {
        self.littleBtn.selected = NO;
        self.bigBtn.selected = YES;
    }
    
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:[SAOverallSetting shareInstance].ticketFontSize.settingsId forKey:@"settingsId"];
    [dict setValue:[SAOverallSetting shareInstance].ticketFontSize.parentId forKey:@"parentId"];
    if (self.littleBtn.selected == YES) {
        [dict setValue:@"0" forKey:@"value"];
    }else {
        [dict setValue:@"1" forKey:@"value"];
    }
    [SANetManager requestWithType:(SkyHttpRequestTypePost) urlString:SA_BASE_URL(@"/system/settings/check") parameters:dict successBlock:^(id responseObject) {
        [SAOverallSetting shareInstance].ticketFontSize.value = dict[@"value"];
    } failureBlock:^(NSString *error) {
        [Prompt popPromptViewWithMsg:error duration:2];
    }];
}

-(void)clickedShowHK {
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setValue:[SAOverallSetting shareInstance].hkSymbol.settingsId forKey:@"settingsId"];
    [parameters setValue:[SAOverallSetting shareInstance].hkSymbol.parentId forKey:@"parentId"];
    if (self.hkongModel.isSelect == YES) {
        [parameters setValue:@"1" forKey:@"value"];
    }else {
        [parameters setValue:@"0" forKey:@"value"];
    }
    [SANetManager requestWithType:(SkyHttpRequestTypePost) urlString:SA_BASE_URL(@"/system/settings/check") parameters:parameters successBlock:^(id responseObject) {
        [SAOverallSetting shareInstance].hkSymbol.value = parameters[@"value"];
    } failureBlock:^(NSString *error) {
        [Prompt popPromptViewWithMsg:error duration:2];
    }];
}

-(void)clickedPreview {
    self.previewView2.hidden = NO;
    NSInteger y = 90;
    if (self.dataMarr[1].isSelect == YES) {//手机
        self.modelPhoneLab.hidden = NO;
        self.modelPhoneLab.y = kScaleNum(y);
        y += 30;
    }else {
        self.modelPhoneLab.hidden = YES;
    }
    
    if (self.dataMarr[0].isSelect == YES) {//会员
        self.modelMembersLab.hidden = NO;
        self.modelMembersLab.y = kScaleNum(y);
        y += 30;
    }else {
        self.modelMembersLab.hidden = YES;
    }
    
    if (self.dataMarr[2].isSelect == YES) {//可用积分
        self.modelAvailableIntegralLab.hidden = NO;
        self.modelAvailableIntegralLab.y = kScaleNum(y);
        y += 30;
    }else {
        self.modelAvailableIntegralLab.hidden = YES;
    }
    
    if (self.dataMarr[3].isSelect == YES) {//本次积分
        self.modelCurrentIntegralLab.hidden = NO;
        self.modelCurrentIntegralLab.y = kScaleNum(y);
        y += 30;
    }else {
        self.modelCurrentIntegralLab.hidden = YES;
    }
    
    if (self.dataMarr[4].isSelect == YES) {
        self.productView.hidden = NO;
        self.productView2.hidden = YES;
        self.productView.y = kScaleNum(y);
        y += 105;
    }else {
        self.productView.hidden = YES;
        self.productView2.hidden = NO;
        self.productView2.y = kScaleNum(y);
        y += 105;
    }

    self.modelSalesLab.y = kScaleNum(y);
    y += 30;
    
    if (self.dataMarr[8].isSelect == YES) {//退货标识
        self.modelReturnTipLab.hidden = NO;
        self.modelReturnTipLab.y = kScaleNum(y);
        y += 30;
    }else {
        self.modelReturnTipLab.hidden = YES;
    }
    
    if (self.dataMarr[5].isSelect == YES) {//整单折扣
        self.modelWholeDiscountLab.hidden = NO;
        self.modelWholeDiscountLab.y = kScaleNum(y);
        y += 30;
    }else {
        self.modelWholeDiscountLab.hidden = YES;
    }
    
    if (self.dataMarr[6].isSelect == YES) {//折扣金额
        self.modelDiscountPriceLab.hidden = NO;
        self.modelDiscountPriceLab.y = kScaleNum(y);
        y += 30;
    }else {
        self.modelDiscountPriceLab.hidden = YES;
    }
    
    if (self.dataMarr[7].isSelect == YES) {//卡劵金额
        self.modelCardPriceLab.hidden = NO;
        self.modelCardPriceLab.y = kScaleNum(y);
        y += 30;
    }else {
        self.modelCardPriceLab.hidden = YES;
    }
    
    y += 15;
    self.modelReceivableLab.y = kScaleNum(y);
    y += 30;
    self.modelPaidinLab.y = kScaleNum(y);
    y += 30;
    
    if (self.dataMarr[10].isSelect == YES) {//可用余额
        self.modelBalanceLab.hidden = NO;
        self.modelBalanceLab.y = kScaleNum(y);
        y += 30;
    }else {
        self.modelBalanceLab.hidden = YES;
    }
    
    if (self.dataMarr[9].isSelect == YES) {//支付方式
        self.modelPayTypeLab.hidden = NO;
        self.modelPayTypeLab.y = kScaleNum(y);
        y += 30;
    }else {
        self.modelPayTypeLab.hidden = YES;
    }
    
    if (self.dataMarr[11].isSelect == YES) {//操作人
        self.modelOperationLab.hidden = NO;
        self.modelOperationLab.y = kScaleNum(y);
        y += 30;
    }else {
        self.modelOperationLab.hidden = YES;
    }
    
    if (self.dataMarr[12].isSelect == YES) {//联系电话
        self.modelContactPhoneLab.hidden = NO;
        self.modelContactPhoneLab.y = kScaleNum(y);
        y += 30;
    }else {
        self.modelContactPhoneLab.hidden = YES;
    }
    
    if (self.dataMarr[13].isSelect == YES) {//联系地址
        self.modelContactAddressLab.hidden = NO;
        self.modelContactAddressLab.y = kScaleNum(y);
        y += 30;
    }else {
        self.modelContactAddressLab.hidden = YES;
    }
   
    if (self.dataMarr[14].isSelect == YES) {//提醒
        self.modelTipLab.hidden = NO;
        self.modelTipLab.y = kScaleNum(y);
        y += 30;
    }else {
        self.modelTipLab.hidden = YES;
    }
    
    if (self.dataMarr[15].isSelect == YES) {//店铺二维码
        self.codeImageV.hidden = NO;
        self.codeImageV.y = kScaleNum(y);
        y += 125;
    }else {
        self.codeImageV.hidden = YES;
    }
    
    if (self.dataMarr[16].isSelect == YES) {//平台信息
        self.modelInformationPlatformLab.hidden = NO;
        self.modelInformationPlatformLab.y = kScaleNum(y);
        y += 30;
        self.modelInformationPlatformLab2.hidden = NO;
        self.modelInformationPlatformLab2.y = kScaleNum(y);
        y += 30;
        self.modelInformationPlatformLab3.hidden = NO;
        self.modelInformationPlatformLab3.y = kScaleNum(y);
        y += 50;
    }else {
        self.modelInformationPlatformLab.hidden = YES;
        self.modelInformationPlatformLab2.hidden = YES;
        self.modelInformationPlatformLab3.hidden = YES;
    }
    
    self.styleView2.contentSize = CGSizeMake(kScreenWidth, kScaleNum(y));
    
    if (self.hkongModel.isSelect == YES) {
        self.modelSalesLab.text = @"销售:1款,1件,88港元";
        self.modelReceivableLab.text = @"应收:88港元";
        self.modelPaidinLab.text = @"实收:88港元";
        self.modelBalanceLab .text = @"可用余额:88港元";
        self.modelPayTypeLab.text = @"支付方式: (现:18港元, 支付宝18港元)";
    }else {
        self.modelReceivableLab.text = @"应收:88元";
        self.modelPaidinLab.text = @"实收:88元";
        self.modelBalanceLab .text = @"可用余额:88元";
        self.modelPayTypeLab.text = @"支付方式: (现:18元, 支付宝18元)";
        self.modelSalesLab.text = @"销售:1款,1件,88元";
    }
    
}

-(void)clickedPreview2 {
    self.barcodeImageV.hidden = YES;
    NSInteger y = 20;
    for (SAPaperSetModel *model in self.laberMarr) {
        NSInteger index = abs([model.valueStr intValue])+1000;
        UILabel *lab = [self.view viewWithTag:index];
        if (index == 1012) {
            if (model.isSelect == YES) {
                self.barcodeImageV.hidden = NO;
                self.barcodeImageV.y = kScaleNum(y);
                y += 50;
                lab.hidden = NO;
                lab.y = kScaleNum(y);
            }else {
                lab.hidden = YES;
            }
        }else {
            if (model.isSelect == YES) {
                lab.hidden = NO;
                lab.y = kScaleNum(y);
                y += 30;
            }else {
                lab.hidden = YES;
            }
        }
    }

    if (y == 20) {
        [Prompt popPromptViewWithMsg:@"最少选择一项" duration:2];
    }else {
        self.previewView.hidden = NO;
        y += 40;
        self.styleView.frame = CGRectMake((kScreenWidth - kScaleNum(202))/2, (kScreenHeight - kScaleNum(y))/2, kScaleNum(202), kScaleNum(y));
    }
    
    if (self.hkongModel.isSelect == YES) {
        self.modePriceLab.text = @"零售价:  ￥100.00港元";
        self.modediscountPriceLab.text = @"折扣价:  ￥80.00港元";
        self.specialPriceLab.text = @"特价:  ￥80.00港元";
        self.vipPriceLab.text = @"会员价:  ￥80.00港元";
    }else {
        self.modePriceLab.text = @"零售价:  ￥100.00元";
        self.modediscountPriceLab.text = @"折扣价:  ￥80.00元";
        self.specialPriceLab.text = @"特价:  ￥80.00元";
        self.vipPriceLab.text = @"会员价:  ￥80.00元";
    }
}

-(void)clickedRightBtn {

    NSInteger height = self.typeMarr.count * 50 + 10;
    if (height > 190) {
        height = 190;
    }
    NSArray *arr = nil;
    UIView *window = [UIApplication sharedApplication].keyWindow;
    if (!self.typeBubbleView) {
        self.typeBubbleView = [[BubbleTableView alloc] initWithLocation:(BubbleLocationDown) bubbleAlignment:(BubbleAlignmentRight) width:120 height:height cellClickBlock:^(NSInteger row, NSString * _Nonnull rowString, NSArray *fromDataArray) {
            self.typeRow = row;
            [self refreshCollection:@(self.typeRow).stringValue];
            [self saveLabelValue];
        } hideBlock:^{
            self.typeBubbleView = nil;
        }];
        [self.typeBubbleView showWithTargetView:self.imageV maskSuperView:window];
        [self.typeBubbleView updateBubble:self.typeMarr fromDataArray:arr];// 更新气泡弹框
        self.typeBubbleView.bubbleCellHeight = 50;
        self.typeBubbleView.selectRow = self.typeRow;
        self.typeBubbleView.bubbleCellTextFont = kFont(15);
        self.typeBubbleView.isBubbleScrollEnabled = YES;
        self.typeBubbleView.bubbleCellTextAlignment = NSTextAlignmentCenter;
    }
}
    
-(void)saveLabelValue {
    NSString *labelValue = [NSString stringWithFormat:@"%zd",self.typeRow];
    NSMutableDictionary *dict2 = [NSMutableDictionary dictionary];
    [dict2 setValue:[SAOverallSetting shareInstance].labelLayout.settingsId forKey:@"settingsId"];
    [dict2 setValue:[SAOverallSetting shareInstance].labelLayout.parentId forKey:@"parentId"];
    [dict2 setValue:labelValue forKey:@"value"];
    [SANetManager requestWithType:(SkyHttpRequestTypePost) urlString:SA_BASE_URL(@"/system/settings/check") parameters:dict2 successBlock:^(id responseObject) {
        [SAOverallSetting shareInstance].labelLayout.value = labelValue;
        
    } failureBlock:^(NSString *error) {
        
    }];
}

- (void)lonePressMoving:(UILongPressGestureRecognizer *)longPress
{
    switch (_longPress.state) {
        case UIGestureRecognizerStateBegan: {
            {
                NSIndexPath *selectIndexPath = [self.collectionView indexPathForItemAtPoint:[_longPress locationInView:self.collectionView]];
                [_collectionView beginInteractiveMovementForItemAtIndexPath:selectIndexPath];
            }
            break;
        }
        case UIGestureRecognizerStateChanged: {
                [self.collectionView updateInteractiveMovementTargetPosition:[longPress locationInView:_longPress.view]];
            break;
        }
        case UIGestureRecognizerStateEnded: {
                [self.collectionView endInteractiveMovement];
            break;
        }
        default: [self.collectionView cancelInteractiveMovement];
            break;
    }
}

-(void)isSelectModel:(SAPaperSetModel *)model {
    NSInteger total = 15;
    if (self.typeRow == 3) {
        total = 4;
    }else if (self.typeRow == 4 || self.typeRow == 0) {
        total = 6;
    }
    NSInteger count = 0;
    BOOL isDiscount = NO;
    BOOL isSpecial = NO;
    for (SAPaperSetModel *newModel in self.laberMarr) {
        if (newModel.isSelect == YES) {
            count++;
        }
        if (newModel.isSelect == YES && [newModel.titleStr isEqualToString:@"显示特价"]) {
            isSpecial = YES;
        }
        if (newModel.isSelect == YES && [newModel.titleStr isEqualToString:@"折扣价"]) {
            isDiscount = YES;
        }
    }
    
    if ([model.titleStr isEqualToString:@"折扣价"] || [model.titleStr isEqualToString:@"显示特价"]) {
        if (isSpecial == YES || isDiscount == YES) {
            [Prompt popPromptViewWithMsg:@"折扣和显示特价只能选择其中一项" duration:3];
            return;
        }
    }

    if (count < total) {
        model.isSelect = YES;
        [self.collectionView reloadData];
    }else {
        NSString *str = [NSString stringWithFormat:@"最多选择%zd项",total];
        [Prompt popPromptViewWithMsg:str duration:2];
    }
}

-(void)clickedDeleteBtn {
    self.previewView.hidden = YES;
}

-(void)clickedDeleteBtn2 {
    self.previewView2.hidden = YES;
}

#pragma mark - initUI
-(void)initUI {
    [self setNavigationItemBackBBIAndTitle:@"票据设置"];
    [self addRightViews:@[self.confirmBtn]];
    self.view.backgroundColor = kBgColor;
    
    [self.view addSubview:self.contentView];
    [self.contentView addSubview:self.lableSetBtn];
    [self.contentView addSubview:self.paperSetBtn];
    
    [self paperViewUI];
    [self lableViewUI];
    [self showPreviewView];
    [self showPreviewView2];
}

-(void)paperViewUI {
    UIView *whiteView = [[UIView alloc] initWithFrame:SARectMake(0, StatusHeight + 60, kBaseScreenWidth, 91)];
    whiteView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:whiteView];
    
    UILabel *title2Lab = [[UILabel alloc] initWithFrame:SARectMake(30, 0, 100, 45)];
    title2Lab.text = @"小票尺寸";
    title2Lab.textColor = kBlackColor;
    title2Lab.font = kFont(16);
    title2Lab.textAlignment = NSTextAlignmentLeft;
    [whiteView addSubview:title2Lab];
    
    UIButton *fiftyEightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    fiftyEightBtn.frame = SARectMake(149, 0, 100, 45);
    [fiftyEightBtn setImage:[UIImage imageNamed:@"shop_blueRound2"] forState:UIControlStateNormal];
    [fiftyEightBtn setImage:[UIImage imageNamed:@"shop_blueCheck2"] forState:UIControlStateSelected];
    [fiftyEightBtn setTitle:@"  58mm" forState:UIControlStateNormal];
    [fiftyEightBtn setTitleColor:kBlackColor forState:UIControlStateNormal];
    fiftyEightBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [fiftyEightBtn addTarget:self action:@selector(clickedSelectBtn:) forControlEvents:UIControlEventTouchUpInside];
    fiftyEightBtn.tag = 58;
    fiftyEightBtn.selected = YES;
    self.fiftyEightBtn = fiftyEightBtn;
    [whiteView addSubview:fiftyEightBtn];
    
    UIButton *eightyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    eightyBtn.frame = SARectMake(260, 0, 100, 45);
    [eightyBtn setImage:[UIImage imageNamed:@"shop_blueRound2"] forState:UIControlStateNormal];
    [eightyBtn setImage:[UIImage imageNamed:@"shop_blueCheck2"] forState:UIControlStateSelected];
    [eightyBtn setTitle:@"  80mm" forState:UIControlStateNormal];
    [eightyBtn setTitleColor:kBlackColor forState:UIControlStateNormal];
    eightyBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [eightyBtn addTarget:self action:@selector(clickedSelectBtn:) forControlEvents:UIControlEventTouchUpInside];
    eightyBtn.tag = 80;
    self.eightyBtn = eightyBtn;
    [whiteView addSubview:eightyBtn];
    
    UIView *line = [[UIView alloc] initWithFrame:SARectMake(0, 45, kBaseScreenWidth, 1)];
    line.backgroundColor = kLineColor;
    [whiteView addSubview:line];
    
    UILabel *title3Lab = [[UILabel alloc] initWithFrame:SARectMake(30, 46, 100, 45)];
    title3Lab.text = @"金额字号";
    title3Lab.textColor = kBlackColor;
    title3Lab.font = kFont(16);
    title3Lab.textAlignment = NSTextAlignmentLeft;
    [whiteView addSubview:title3Lab];
    
    UIButton *littleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    littleBtn.frame = SARectMake(149, 46, 100, 45);
    [littleBtn setImage:[UIImage imageNamed:@"shop_blueRound2"] forState:UIControlStateNormal];
    [littleBtn setImage:[UIImage imageNamed:@"shop_blueCheck2"] forState:UIControlStateSelected];
    [littleBtn setTitle:@"  小" forState:UIControlStateNormal];
    [littleBtn setTitleColor:kBlackColor forState:UIControlStateNormal];
    littleBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [littleBtn addTarget:self action:@selector(clickedSelectFontBtn:) forControlEvents:UIControlEventTouchUpInside];
    littleBtn.tag = 100;
    littleBtn.selected = YES;
    self.littleBtn = littleBtn;
    [whiteView addSubview:littleBtn];
    
    UIButton *bigBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    bigBtn.frame = SARectMake(260, 46, 100, 45);
    [bigBtn setImage:[UIImage imageNamed:@"shop_blueRound2"] forState:UIControlStateNormal];
    [bigBtn setImage:[UIImage imageNamed:@"shop_blueCheck2"] forState:UIControlStateSelected];
    [bigBtn setTitle:@"  大" forState:UIControlStateNormal];
    [bigBtn setTitleColor:kBlackColor forState:UIControlStateNormal];
    bigBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [bigBtn addTarget:self action:@selector(clickedSelectFontBtn:) forControlEvents:UIControlEventTouchUpInside];
    bigBtn.tag = 101;
    self.bigBtn = bigBtn;
    [whiteView addSubview:bigBtn];
    
    [self.view addSubview:self.tableView];
}

-(void)lableViewUI {
    UIView *lableView = [[UIView alloc] initWithFrame:CGRectMake(0, kScaleNum(StatusHeight + 60), kScreenWidth, kScreenHeight - kScaleNum(StatusHeight + 60))];
    lableView.backgroundColor = kBgColor;
    [self.view addSubview:lableView];
    self.lableView = lableView;
    self.lableView.hidden = YES;
    
    UIView *whiteView = [[UIView alloc] initWithFrame:SARectMake(0, 0, kBaseScreenWidth, 45)];
    whiteView.backgroundColor = [UIColor whiteColor];
    [lableView addSubview:whiteView];
    
    UILabel *sizeTitleLab = [[UILabel alloc] initWithFrame:SARectMake(30, 0, 100, 45)];
    sizeTitleLab.textColor = kBlackColor;
    sizeTitleLab.font = kFont(16);
    sizeTitleLab.text = @"标签尺寸";
    [lableView addSubview:sizeTitleLab];
    
    UILabel *sizeLab = [[UILabel alloc] initWithFrame:SARectMake(kBaseScreenWidth - 137, 0, 100, 45)];
    sizeLab.textColor = kBlackColor;
    sizeLab.font = kFont(16);
    sizeLab.text = @"40*60mm";
    sizeLab.textAlignment = NSTextAlignmentRight;
    [lableView addSubview:sizeLab];
    self.sizeLab = sizeLab;
    
    UIImageView *imageV = [[UIImageView alloc] initWithFrame:SARectMake(kBaseScreenWidth - 30, 11, 23, 23)];
    imageV.image = [UIImage imageNamed:@"Sale_rightArrow2"];
    imageV.contentMode = UIViewContentModeScaleAspectFit;
    [lableView addSubview:imageV];
    self.imageV = imageV;
    
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame = SARectMake(kBaseScreenWidth - 250, 0, 250, 45);
    [rightBtn addTarget:self action:@selector(clickedRightBtn) forControlEvents:UIControlEventTouchUpInside];
    [lableView addSubview:rightBtn];
    
    [self.lableView addSubview:self.collectionView];
    
    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(lonePressMoving:)];
    [self.collectionView addGestureRecognizer:longPress];
    self.longPress = longPress;
}

-(void)showPreviewView {
    UIView *previewView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    previewView.backgroundColor = kColor(0, 0, 0, 0.3);
    [self.view addSubview:previewView];
    self.previewView = previewView;
    self.previewView.hidden = YES;
    
    UIButton *deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    deleteBtn.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
    [deleteBtn addTarget:self action:@selector(clickedDeleteBtn) forControlEvents:UIControlEventTouchUpInside];
    [previewView addSubview:deleteBtn];
    
    UIView *styleView = [[UIView alloc] initWithFrame:CGRectMake((kScreenWidth - kScaleNum(202))/2, (kScreenHeight - kScaleNum(460))/2, kScaleNum(202), kScaleNum(460))];
    styleView.backgroundColor = [UIColor whiteColor];
    styleView.userInteractionEnabled = NO;
    styleView.layer.cornerRadius = kScaleNum(3);
    styleView.layer.masksToBounds = YES;
    [previewView addSubview:styleView];
    self.styleView = styleView;
    
    UILabel *modelTitleLab = [[UILabel alloc] initWithFrame:SARectMake(0, 20, 202, 20)];
    modelTitleLab.text = @"潮牌店铺";
    modelTitleLab.textColor = kBlackColor;
    modelTitleLab.font = kFont(16);
    modelTitleLab.textAlignment = NSTextAlignmentCenter;
    [styleView addSubview:modelTitleLab];
    modelTitleLab.tag = 1000;
    
    UILabel *modeOrderIdLab = [[UILabel alloc] initWithFrame:SARectMake(25, 20, 175, 20)];
    modeOrderIdLab.text = @"款号:  001";
    modeOrderIdLab.textColor = kBlackColor;
    modeOrderIdLab.font = kFont(16);
    modeOrderIdLab.textAlignment = NSTextAlignmentLeft;
    [styleView addSubview:modeOrderIdLab];
    modeOrderIdLab.tag = 1001;
    
    UILabel *modeNameLab = [[UILabel alloc] initWithFrame:SARectMake(25, 20, 175, 20)];
    modeNameLab.text = @"名称:  毛衣";
    modeNameLab.textColor = kBlackColor;
    modeNameLab.font = kFont(16);
    modeNameLab.textAlignment = NSTextAlignmentLeft;
    [styleView addSubview:modeNameLab];
    modeNameLab.tag = 1002;
    
    UILabel *modeColourLab = [[UILabel alloc] initWithFrame:SARectMake(25, 20, 175, 20)];
    modeColourLab.text = @"颜色:  白色";
    modeColourLab.textColor = kBlackColor;
    modeColourLab.font = kFont(16);
    modeColourLab.textAlignment = NSTextAlignmentLeft;
    [styleView addSubview:modeColourLab];
    modeColourLab.tag = 1003;
    
    UILabel *modeSizeLab = [[UILabel alloc] initWithFrame:SARectMake(25, 20, 175, 20)];
    modeSizeLab.text = @"尺码:  S";
    modeSizeLab.textColor = kBlackColor;
    modeSizeLab.font = kFont(16);
    modeSizeLab.textAlignment = NSTextAlignmentLeft;
    [styleView addSubview:modeSizeLab];
    modeSizeLab.tag = 1004;
    
    UILabel *modePriceLab = [[UILabel alloc] initWithFrame:SARectMake(25, 20, 175, 20)];
    modePriceLab.text = @"零售价:  ￥100.00元";
    modePriceLab.textColor = kBlackColor;
    modePriceLab.font = kFont(16);
    modePriceLab.textAlignment = NSTextAlignmentLeft;
    [styleView addSubview:modePriceLab];
    modePriceLab.tag = 1005;
    self.modePriceLab = modePriceLab;
    
    UILabel *modediscountPriceLab = [[UILabel alloc] initWithFrame:SARectMake(25, 20, 175, 20)];
    modediscountPriceLab.text = @"折扣价:  ￥80.00元";
    modediscountPriceLab.textColor = kBlackColor;
    modediscountPriceLab.font = kFont(16);
    modediscountPriceLab.textAlignment = NSTextAlignmentLeft;
    [styleView addSubview:modediscountPriceLab];
    modediscountPriceLab.tag = 1006;
    self.modediscountPriceLab = modediscountPriceLab;
    
    UILabel *modedCompositionLab = [[UILabel alloc] initWithFrame:SARectMake(25, 20, 175, 20)];
    modedCompositionLab.text = @"成分含量:  80%粘纤";
    modedCompositionLab.textColor = kBlackColor;
    modedCompositionLab.font = kFont(16);
    modedCompositionLab.textAlignment = NSTextAlignmentLeft;
    [styleView addSubview:modedCompositionLab];
    modedCompositionLab.tag = 1007;
    
    UILabel *modedStandardLab = [[UILabel alloc] initWithFrame:SARectMake(25, 20, 175, 20)];
    modedStandardLab.text = @"产品标准:  CB/T222-21";
    modedStandardLab.textColor = kBlackColor;
    modedStandardLab.font = kFont(16);
    modedStandardLab.textAlignment = NSTextAlignmentLeft;
    [styleView addSubview:modedStandardLab];
    modedStandardLab.tag = 1008;
    
    UILabel *modelSecurityLab = [[UILabel alloc] initWithFrame:SARectMake(25, 20, 175, 20)];
    modelSecurityLab.text = @"安全类别:  B类";
    modelSecurityLab.textColor = kBlackColor;
    modelSecurityLab.font = kFont(16);
    modelSecurityLab.textAlignment = NSTextAlignmentLeft;
    [styleView addSubview:modelSecurityLab];
    modelSecurityLab.tag = 1009;
    
    UILabel *modelQualityLab = [[UILabel alloc] initWithFrame:SARectMake(25, 20, 175, 20)];
    modelQualityLab.text = @"质量等级:  A类";
    modelQualityLab.textColor = kBlackColor;
    modelQualityLab.font = kFont(16);
    modelQualityLab.textAlignment = NSTextAlignmentLeft;
    [styleView addSubview:modelQualityLab];
    modelQualityLab.tag = 1010;
    
    UILabel *modelWashingLab = [[UILabel alloc] initWithFrame:SARectMake(25, 20, 175, 20)];
    modelWashingLab.text = @"洗涤方式:  手洗";
    modelWashingLab.textColor = kBlackColor;
    modelWashingLab.font = kFont(16);
    modelWashingLab.textAlignment = NSTextAlignmentLeft;
    [styleView addSubview:modelWashingLab];
    modelWashingLab.tag = 1011;
    
    UILabel *modelBrandLab = [[UILabel alloc] initWithFrame:SARectMake(25, 20, 175, 20)];
    modelBrandLab.text = @"品牌:  爱马仕";
    modelBrandLab.textColor = kBlackColor;
    modelBrandLab.font = kFont(16);
    modelBrandLab.textAlignment = NSTextAlignmentLeft;
    [styleView addSubview:modelBrandLab];
    modelBrandLab.tag = 1013;
    
    UILabel *specialPriceLab = [[UILabel alloc] initWithFrame:SARectMake(25, 20, 175, 20)];
    specialPriceLab.text = @"特价:  ￥80.00元";
    specialPriceLab.textColor = kBlackColor;
    specialPriceLab.font = kFont(16);
    specialPriceLab.textAlignment = NSTextAlignmentLeft;
    [styleView addSubview:specialPriceLab];
    specialPriceLab.tag = 1014;
    self.specialPriceLab = specialPriceLab;
    
    UILabel *vipPriceLab = [[UILabel alloc] initWithFrame:SARectMake(25, 20, 175, 20)];
    vipPriceLab.text = @"会员价:  ￥80.00元";
    vipPriceLab.textColor = kBlackColor;
    vipPriceLab.font = kFont(16);
    vipPriceLab.textAlignment = NSTextAlignmentLeft;
    [styleView addSubview:vipPriceLab];
    vipPriceLab.tag = 1015;
    self.vipPriceLab = vipPriceLab;
    
    UILabel *groupLab = [[UILabel alloc] initWithFrame:SARectMake(25, 20, 175, 20)];
    groupLab.text = @"场地:  深圳市宝安区";
    groupLab.textColor = kBlackColor;
    groupLab.font = kFont(16);
    groupLab.textAlignment = NSTextAlignmentLeft;
    [styleView addSubview:groupLab];
    groupLab.tag = 1016;
    self.groupLab = groupLab;
    
    UILabel *dealerLab = [[UILabel alloc] initWithFrame:SARectMake(25, 20, 175, 20)];
    dealerLab.text = @"经销商:  衣点通";
    dealerLab.textColor = kBlackColor;
    dealerLab.font = kFont(16);
    dealerLab.textAlignment = NSTextAlignmentLeft;
    [styleView addSubview:dealerLab];
    dealerLab.tag = 1017;
    self.dealerLab = dealerLab;
    
    NSString *barcode = @"12312312311231231231";
    UIImageView *barcodeImageV = [[UIImageView alloc] initWithFrame:SARectMake(25, 20, 152, 45)];
    [styleView addSubview:barcodeImageV];
    self.barcodeImageV = barcodeImageV;
    self.barcodeImageV.image = [self resizeCodeWithString:@"12312312311231231231" BCSize:CGSizeMake(kScaleNum(152), kScaleNum(45))];
    
    UILabel *barcodeLab = [[UILabel alloc] initWithFrame:SARectMake(0, 20, 202, 20)];
    barcodeLab.text = barcode;
    barcodeLab.textColor = kBlackColor;
    barcodeLab.font = kFont(16);
    barcodeLab.textAlignment = NSTextAlignmentCenter;
    [styleView addSubview:barcodeLab];
    barcodeLab.tag = 1012;
}

-(void)showPreviewView2 {
    UIView *previewView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    previewView.backgroundColor = kColor(0, 0, 0, 0.3);
    [self.view addSubview:previewView];
    self.previewView2 = previewView;
    self.previewView2.hidden = YES;
    
    UIView *whiteView = [[UIView alloc] initWithFrame:SARectMake(0, 0, kBaseScreenWidth, 40)];
    whiteView.backgroundColor = [UIColor whiteColor];
    [previewView addSubview:whiteView];
    
    UIScrollView *styleView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, kScaleNum(35), kScreenWidth, kScreenHeight - kScaleNum(35))];
    styleView.backgroundColor = [UIColor whiteColor];
    styleView.contentSize = SASizeMake(kBaseScreenWidth, 1000);
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickedDeleteBtn2)];
    [styleView addGestureRecognizer:tap];
    [previewView addSubview:styleView];
    self.styleView2 = styleView;
    
    UILabel *modelClothingLab = [[UILabel alloc] initWithFrame:SARectMake(0, 0, kBaseScreenWidth, 20)];
    modelClothingLab.text = @"服装店";
    modelClothingLab.textColor = kBlackColor;
    modelClothingLab.font = kFont(18);
    modelClothingLab.textAlignment = NSTextAlignmentCenter;
    [styleView addSubview:modelClothingLab];
    
    UILabel *modelOrderLab = [[UILabel alloc] initWithFrame:SARectMake(20, 30, kBaseScreenWidth - 40, 20)];
    modelOrderLab.text = @"订单:XS0899";
    modelOrderLab.textColor = kBlackColor;
    modelOrderLab.font = kFont(16);
    modelOrderLab.textAlignment = NSTextAlignmentLeft;
    [styleView addSubview:modelOrderLab];
    
    UILabel *modelDateLab = [[UILabel alloc] initWithFrame:SARectMake(20, 60, kBaseScreenWidth - 40, 20)];
    modelDateLab.text = @"日期:2021-05-07";
    modelDateLab.textColor = kBlackColor;
    modelDateLab.font = kFont(16);
    modelDateLab.textAlignment = NSTextAlignmentLeft;
    [styleView addSubview:modelDateLab];
    
    UILabel *modelPhoneLab = [[UILabel alloc] initWithFrame:SARectMake(20, 200, kBaseScreenWidth - 40, 20)];
    modelPhoneLab.text = @"手机:188****8888";
    modelPhoneLab.textColor = kBlackColor;
    modelPhoneLab.font = kFont(16);
    modelPhoneLab.textAlignment = NSTextAlignmentLeft;
    [styleView addSubview:modelPhoneLab];
    self.modelPhoneLab = modelPhoneLab;
    
    UILabel *modelMembersLab = [[UILabel alloc] initWithFrame:SARectMake(20, 200, kBaseScreenWidth - 40, 20)];
    modelMembersLab.text = @"会员:会员1";
    modelMembersLab.textColor = kBlackColor;
    modelMembersLab.font = kFont(16);
    modelMembersLab.textAlignment = NSTextAlignmentLeft;
    [styleView addSubview:modelMembersLab];
    self.modelMembersLab = modelMembersLab;
    
    UILabel *modelAvailableIntegralLab = [[UILabel alloc] initWithFrame:SARectMake(20, 200, kBaseScreenWidth - 40, 20)];
    modelAvailableIntegralLab.text = @"可用积分:100";
    modelAvailableIntegralLab.textColor = kBlackColor;
    modelAvailableIntegralLab.font = kFont(16);
    modelAvailableIntegralLab.textAlignment = NSTextAlignmentLeft;
    [styleView addSubview:modelAvailableIntegralLab];
    self.modelAvailableIntegralLab = modelAvailableIntegralLab;
    
    UILabel *modelCurrentIntegralLab = [[UILabel alloc] initWithFrame:SARectMake(20, 200, kBaseScreenWidth - 40, 20)];
    modelCurrentIntegralLab.text = @"本次积分:100";
    modelCurrentIntegralLab.textColor = kBlackColor;
    modelCurrentIntegralLab.font = kFont(16);
    modelCurrentIntegralLab.textAlignment = NSTextAlignmentLeft;
    [styleView addSubview:modelCurrentIntegralLab];
    self.modelCurrentIntegralLab = modelCurrentIntegralLab;
    
    UIView *productView = [[UIView alloc] initWithFrame:SARectMake(0, 300, kBaseScreenWidth, 105)];
    [styleView addSubview:productView];
    UIView *line = [[UIView alloc] initWithFrame:SARectMake(0, 0, kBaseScreenWidth, 1)];
    line.backgroundColor = kBlackColor;
    [productView addSubview:line];
    self.productView = productView;
    
    NSArray *arr1 = @[@"商品", @"数量", @"单价", @"折扣", @"金额"];
    for (int i = 0; i < arr1.count; i++) {
        UILabel *titleLab = [[UILabel alloc] init];
        titleLab.text = arr1[i];
        titleLab.font = kFont(16);
        titleLab.textColor = kBlackColor;
        [productView addSubview:titleLab];
        titleLab.textAlignment = NSTextAlignmentCenter;
        if (i == 0) {
            titleLab.frame = CGRectMake(kScaleNum(20), 0, kScaleNum(60), kScaleNum(35));
            titleLab.textAlignment = NSTextAlignmentLeft;
        }else if (i == 1) {
            titleLab.frame = CGRectMake(kScaleNum(101), 0, kScaleNum(65), kScaleNum(35));
        }else if (i == 2) {
            titleLab.frame = CGRectMake(kScaleNum(179), 0, kScaleNum(65), kScaleNum(35));
        }else if (i == 3) {
            titleLab.frame = CGRectMake(kScaleNum(236), 0, kScaleNum(65), kScaleNum(35));
        }else if (i == 4) {
            titleLab.frame = CGRectMake(kScaleNum(296), 0, kScaleNum(78), kScaleNum(35));
        }
    }
    
    UIView *line2 = [[UIView alloc] initWithFrame:SARectMake(0, 34, kBaseScreenWidth, 1)];
    line2.backgroundColor = kBlackColor;
    [productView addSubview:line2];
    
    UILabel *modelProductNameLab = [[UILabel alloc] initWithFrame:SARectMake(20, 45, kBaseScreenWidth - 40, 20)];
    modelProductNameLab.text = @"夏季短袖";
    modelProductNameLab.textColor = kBlackColor;
    modelProductNameLab.font = kFont(16);
    modelProductNameLab.textAlignment = NSTextAlignmentLeft;
    [productView addSubview:modelProductNameLab];
    
    NSArray *arr2 = @[@"均色/均码", @"1", @"88", @"100%", @"88"];
    for (int i = 0; i < arr2.count; i++) {
        UILabel *titleLab = [[UILabel alloc] init];
        titleLab.text = arr2[i];
        titleLab.font = kFont(16);
        titleLab.textColor = kBlackColor;
        [productView addSubview:titleLab];
        titleLab.textAlignment = NSTextAlignmentCenter;
        if (i == 0) {
            titleLab.frame = CGRectMake(kScaleNum(20), kScaleNum(75), kScaleNum(80), kScaleNum(20));
            titleLab.textAlignment = NSTextAlignmentLeft;
        }else if (i == 1) {
            titleLab.frame = CGRectMake(kScaleNum(101), kScaleNum(75), kScaleNum(65), kScaleNum(20));
        }else if (i == 2) {
            titleLab.frame = CGRectMake(kScaleNum(179), kScaleNum(75), kScaleNum(65), kScaleNum(20));
        }else if (i == 3) {
            titleLab.frame = CGRectMake(kScaleNum(236), kScaleNum(75), kScaleNum(65), kScaleNum(20));
        }else if (i == 4) {
            titleLab.frame = CGRectMake(kScaleNum(296), kScaleNum(75), kScaleNum(78), kScaleNum(20));
        }
    }
    
    UIView *line3 = [[UIView alloc] initWithFrame:SARectMake(0, 97, kBaseScreenWidth, 1)];
    line3.backgroundColor = kBlackColor;
    [productView addSubview:line3];
    
    
    UIView *productView2 = [[UIView alloc] initWithFrame:SARectMake(0, 300, kBaseScreenWidth, 105)];
    [styleView addSubview:productView2];
    UIView *line4 = [[UIView alloc] initWithFrame:SARectMake(0, 0, kBaseScreenWidth, 1)];
    line4.backgroundColor = kBlackColor;
    [productView2 addSubview:line4];
    self.productView2 = productView2;
    
    NSArray *arr3 = @[@"商品", @"数量", @"单价", @"金额"];
    for (int i = 0; i < arr3.count; i++) {
        UILabel *titleLab = [[UILabel alloc] init];
        titleLab.text = arr3[i];
        titleLab.font = kFont(16);
        titleLab.textColor = kBlackColor;
        [productView2 addSubview:titleLab];
        titleLab.textAlignment = NSTextAlignmentCenter;
        if (i == 0) {
            titleLab.frame = CGRectMake(kScaleNum(20), 0, kScaleNum(60), kScaleNum(35));
            titleLab.textAlignment = NSTextAlignmentLeft;
        }else if (i == 1) {
            titleLab.frame = CGRectMake(kScaleNum(101), 0, kScaleNum(85), kScaleNum(35));
        }else if (i == 2) {
            titleLab.frame = CGRectMake(kScaleNum(199), 0, kScaleNum(85), kScaleNum(35));
        }else if (i == 3) {
            titleLab.frame = CGRectMake(kScaleNum(276), 0, kScaleNum(85), kScaleNum(35));
        }
    }
    
    UIView *line5 = [[UIView alloc] initWithFrame:SARectMake(0, 34, kBaseScreenWidth, 1)];
    line5.backgroundColor = kBlackColor;
    [productView2 addSubview:line5];
    
    UILabel *modelProductNameLab2 = [[UILabel alloc] initWithFrame:SARectMake(20, 45, kBaseScreenWidth - 40, 20)];
    modelProductNameLab2.text = @"夏季短袖";
    modelProductNameLab2.textColor = kBlackColor;
    modelProductNameLab2.font = kFont(16);
    modelProductNameLab2.textAlignment = NSTextAlignmentLeft;
    [productView2 addSubview:modelProductNameLab2];
    
    NSArray *arr4 = @[@"均色/均码", @"1", @"88", @"88"];
    for (int i = 0; i < arr4.count; i++) {
        UILabel *titleLab = [[UILabel alloc] init];
        titleLab.text = arr4[i];
        titleLab.font = kFont(16);
        titleLab.textColor = kBlackColor;
        [productView2 addSubview:titleLab];
        titleLab.textAlignment = NSTextAlignmentCenter;
        if (i == 0) {
            titleLab.frame = CGRectMake(kScaleNum(20), kScaleNum(75), kScaleNum(80), kScaleNum(20));
            titleLab.textAlignment = NSTextAlignmentLeft;
        }else if (i == 1) {
            titleLab.frame = CGRectMake(kScaleNum(101), kScaleNum(75), kScaleNum(85), kScaleNum(20));
        }else if (i == 2) {
            titleLab.frame = CGRectMake(kScaleNum(199), kScaleNum(75), kScaleNum(85), kScaleNum(20));
        }else if (i == 3) {
            titleLab.frame = CGRectMake(kScaleNum(276), kScaleNum(75), kScaleNum(85), kScaleNum(20));
        }
    }
    
    UIView *line6 = [[UIView alloc] initWithFrame:SARectMake(0, 97, kBaseScreenWidth, 1)];
    line6.backgroundColor = kBlackColor;
    [productView2 addSubview:line6];
    
    
    UILabel *modelSalesLab = [[UILabel alloc] initWithFrame:SARectMake(20, 200, kBaseScreenWidth - 40, 20)];
    modelSalesLab.text = @"销售:1款,1件,88元";
    modelSalesLab.textColor = kBlackColor;
    modelSalesLab.font = kFont(16);
    modelSalesLab.textAlignment = NSTextAlignmentLeft;
    [styleView addSubview:modelSalesLab];
    self.modelSalesLab = modelSalesLab;
    
    UILabel *modelReturnTipLab = [[UILabel alloc] initWithFrame:SARectMake(20, 200, kBaseScreenWidth - 40, 20)];
    modelReturnTipLab.text = @"'-'号代表退货";
    modelReturnTipLab.textColor = kBlackColor;
    modelReturnTipLab.font = kFont(16);
    modelReturnTipLab.textAlignment = NSTextAlignmentLeft;
    [styleView addSubview:modelReturnTipLab];
    self.modelReturnTipLab = modelReturnTipLab;
    
    UILabel *modelWholeDiscountLab = [[UILabel alloc] initWithFrame:SARectMake(20, 200, kBaseScreenWidth - 40, 20)];
    modelWholeDiscountLab.text = @"整单折扣:100%";
    modelWholeDiscountLab.textColor = kBlackColor;
    modelWholeDiscountLab.font = kFont(16);
    modelWholeDiscountLab.textAlignment = NSTextAlignmentLeft;
    [styleView addSubview:modelWholeDiscountLab];
    self.modelWholeDiscountLab = modelWholeDiscountLab;
    
    UILabel *modelDiscountPriceLab = [[UILabel alloc] initWithFrame:SARectMake(20, 200, kBaseScreenWidth - 40, 20)];
    modelDiscountPriceLab.text = @"折扣金额:88";
    modelDiscountPriceLab.textColor = kBlackColor;
    modelDiscountPriceLab.font = kFont(16);
    modelDiscountPriceLab.textAlignment = NSTextAlignmentLeft;
    [styleView addSubview:modelDiscountPriceLab];
    self.modelDiscountPriceLab = modelDiscountPriceLab;
    
    UILabel *modelCardPriceLab = [[UILabel alloc] initWithFrame:SARectMake(20, 200, kBaseScreenWidth - 40, 20)];
    modelCardPriceLab.text = @"卡劵金额:88";
    modelCardPriceLab.textColor = kBlackColor;
    modelCardPriceLab.font = kFont(16);
    modelCardPriceLab.textAlignment = NSTextAlignmentLeft;
    [styleView addSubview:modelCardPriceLab];
    self.modelCardPriceLab = modelCardPriceLab;
    
    UILabel *modelReceivableLab = [[UILabel alloc] initWithFrame:SARectMake(20, 200, kBaseScreenWidth - 40, 20)];
    modelReceivableLab.text = @"应收:88元";
    modelReceivableLab.textColor = kBlackColor;
    modelReceivableLab.font = kFont(16);
    modelReceivableLab.textAlignment = NSTextAlignmentLeft;
    [styleView addSubview:modelReceivableLab];
    self.modelReceivableLab = modelReceivableLab;
    
    UILabel *modelPaidinLab = [[UILabel alloc] initWithFrame:SARectMake(20, 200, kBaseScreenWidth - 40, 20)];
    modelPaidinLab.text = @"实收:88元";
    modelPaidinLab.textColor = kBlackColor;
    modelPaidinLab.font = kFont(16);
    modelPaidinLab.textAlignment = NSTextAlignmentLeft;
    [styleView addSubview:modelPaidinLab];
    self.modelPaidinLab = modelPaidinLab;
    
    UILabel *modelBalanceLab = [[UILabel alloc] initWithFrame:SARectMake(20, 200, kBaseScreenWidth - 40, 20)];
    modelBalanceLab.text = @"可用余额:88元";
    modelBalanceLab.textColor = kBlackColor;
    modelBalanceLab.font = kFont(16);
    modelBalanceLab.textAlignment = NSTextAlignmentLeft;
    [styleView addSubview:modelBalanceLab];
    self.modelBalanceLab = modelBalanceLab;
    
    UILabel *modelPayTypeLab = [[UILabel alloc] initWithFrame:SARectMake(20, 200, kBaseScreenWidth - 40, 20)];
    modelPayTypeLab.text = @"支付方式: (现:18元, 支付宝18)";
    modelPayTypeLab.textColor = kBlackColor;
    modelPayTypeLab.font = kFont(16);
    modelPayTypeLab.textAlignment = NSTextAlignmentLeft;
    [styleView addSubview:modelPayTypeLab];
    self.modelPayTypeLab = modelPayTypeLab;
    
    UILabel *modelOperationLab = [[UILabel alloc] initWithFrame:SARectMake(20, 200, kBaseScreenWidth - 40, 20)];
    modelOperationLab.text = @"操作人:刘德华";
    modelOperationLab.textColor = kBlackColor;
    modelOperationLab.font = kFont(16);
    modelOperationLab.textAlignment = NSTextAlignmentLeft;
    [styleView addSubview:modelOperationLab];
    self.modelOperationLab = modelOperationLab;
    
    UILabel *modelContactPhoneLab = [[UILabel alloc] initWithFrame:SARectMake(20, 200, kBaseScreenWidth - 40, 20)];
    modelContactPhoneLab.text = @"联系电话: 18888888888";
    modelContactPhoneLab.textColor = kBlackColor;
    modelContactPhoneLab.font = kFont(16);
    modelContactPhoneLab.textAlignment = NSTextAlignmentLeft;
    [styleView addSubview:modelContactPhoneLab];
    self.modelContactPhoneLab = modelContactPhoneLab;
    
    UILabel *modelContactAddressLab = [[UILabel alloc] initWithFrame:SARectMake(20, 200, kBaseScreenWidth - 40, 20)];
    modelContactAddressLab.text = @"联系地址: 广东省深圳市宝安区西乡街道";
    modelContactAddressLab.textColor = kBlackColor;
    modelContactAddressLab.font = kFont(16);
    modelContactAddressLab.textAlignment = NSTextAlignmentLeft;
    [styleView addSubview:modelContactAddressLab];
    self.modelContactAddressLab = modelContactAddressLab;
    
    UILabel *modelTipLab = [[UILabel alloc] initWithFrame:SARectMake(20, 200, kBaseScreenWidth - 40, 20)];
    modelTipLab.text = @"*钱款、件数请当面点清，离店概不负责";
    modelTipLab.textColor = kBlackColor;
    modelTipLab.font = kFont(16);
    modelTipLab.textAlignment = NSTextAlignmentLeft;
    [styleView addSubview:modelTipLab];
    self.modelTipLab = modelTipLab;
    
    UIImageView *codeImageV = [[UIImageView alloc] initWithFrame:CGRectMake(kScaleNum(125), 0, kScaleNum(125), kScaleNum(125))];
    [styleView addSubview:codeImageV];
    self.codeImageV = codeImageV;
    self.codeImageV.image = [self createCodeWithString:@"wxp://f2f0JpJvdm0fbMuXKYAJA-PTzbk8Y8bRdOQN08CUJ6cxnho" size:self.codeImageV.size CodeFomart:kBarcodeFormatQRCode];

    UILabel *modelInformationPlatformLab = [[UILabel alloc] initWithFrame:SARectMake(20, 200, kBaseScreenWidth - 40, 20)];
    modelInformationPlatformLab.text = @"深圳市孚云信息科技有限公司";
    modelInformationPlatformLab.textColor = kBlackColor;
    modelInformationPlatformLab.font = kFont(16);
    modelInformationPlatformLab.textAlignment = NSTextAlignmentCenter;
    [styleView addSubview:modelInformationPlatformLab];
    self.modelInformationPlatformLab = modelInformationPlatformLab;
    
    UILabel *modelInformationPlatformLab2 = [[UILabel alloc] initWithFrame:SARectMake(20, 200, kBaseScreenWidth - 40, 20)];
    modelInformationPlatformLab2.text = @"衣点通服装管理系统";
    modelInformationPlatformLab2.textColor = kBlackColor;
    modelInformationPlatformLab2.font = kFont(16);
    modelInformationPlatformLab2.textAlignment = NSTextAlignmentCenter;
    [styleView addSubview:modelInformationPlatformLab2];
    self.modelInformationPlatformLab2 = modelInformationPlatformLab2;
    
    UILabel *modelInformationPlatformLab3 = [[UILabel alloc] initWithFrame:SARectMake(20, 200, kBaseScreenWidth - 40, 20)];
    modelInformationPlatformLab3.text = @"客服热线电话:0755-27804689";
    modelInformationPlatformLab3.textColor = kBlackColor;
    modelInformationPlatformLab3.font = kFont(16);
    modelInformationPlatformLab3.textAlignment = NSTextAlignmentCenter;
    [styleView addSubview:modelInformationPlatformLab3];
    self.modelInformationPlatformLab3 = modelInformationPlatformLab3;
    
}

#pragma mark - lazy
-(UIView *)contentView {
    if (!_contentView) {
        _contentView = [[UIView alloc] initWithFrame:CGRectMake((kScreenWidth - kScaleNum(240))/2, kScaleNum(StatusHeight + 10), kScaleNum(240), kScaleNum(40))];
        _contentView.layer.cornerRadius = kScaleNum(3);
        _contentView.layer.masksToBounds = YES;
    }
    return _contentView;
}

-(UIButton *)lableSetBtn {
    if (!_lableSetBtn) {
        _lableSetBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _lableSetBtn.frame = SARectMake(120, 0, 120, 40);
        _lableSetBtn.backgroundColor = [UIColor whiteColor];
        [_lableSetBtn setTitle:@"标签排版" forState:UIControlStateNormal];
        [_lableSetBtn setTitleColor:kBuleColor forState:UIControlStateNormal];
        [_lableSetBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
        _lableSetBtn.titleLabel.font = kFont(16);
        _lableSetBtn.selected = NO;
        [_lableSetBtn addTarget:self action:@selector(clickedLableSetBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _lableSetBtn;
}

-(UIButton *)paperSetBtn {
    if (!_paperSetBtn) {
        _paperSetBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _paperSetBtn.frame = SARectMake(0, 0, 120, 40);
        _paperSetBtn.backgroundColor = kBuleColor;
        [_paperSetBtn setTitle:@"小票模板" forState:UIControlStateNormal];
        [_paperSetBtn setTitleColor:kBuleColor forState:UIControlStateNormal];
        [_paperSetBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
        _paperSetBtn.titleLabel.font = kFont(16);
        _paperSetBtn.selected = YES;
        [_paperSetBtn addTarget:self action:@selector(clickedPaperSetBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _paperSetBtn;
}

-(UIButton *)confirmBtn {
    if (!_confirmBtn) {
        _confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_confirmBtn setTitle:@"保存" forState:UIControlStateNormal];
        [_confirmBtn setTitleColor:kBuleColor forState:UIControlStateNormal];
        _confirmBtn.titleLabel.font = kFont(18);
        _confirmBtn.frame = SARectMake(254, 0, 53, 44);
        [_confirmBtn addTarget:self action:@selector(clickedConfirmBtn) forControlEvents:UIControlEventTouchUpInside];
    }
    return _confirmBtn;
}

-(UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, kScaleNum(StatusHeight + 152), kScreenWidth, kScreenHeight - kScaleNum(StatusHeight + 152)) style:UITableViewStyleGrouped];
        _tableView.backgroundColor = kBgColor;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.showsHorizontalScrollIndicator = NO;
        if (@available(iOS 11.0, *)) {
            _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }
        _tableView.bounces = NO;
        _tableView.estimatedRowHeight = 0;
        _tableView.estimatedSectionHeaderHeight = 0;
        _tableView.estimatedSectionFooterHeight = 0;
        [_tableView registerClass:[SAPaperSetTableViewCell class] forCellReuseIdentifier:@"SAPaperSetTableViewCell"];
        [_tableView registerClass:[SAPaperSetFootView class] forHeaderFooterViewReuseIdentifier:@"SAPaperSetFootView"];
    }
    return _tableView;
}

-(UICollectionView *)collectionView {
    if (!_collectionView) {
        UICollectionViewFlowLayout *flowLayout = [UICollectionViewFlowLayout new];
        flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
        flowLayout.itemSize = CGSizeMake(kScreenWidth, kScaleNum(45));
        flowLayout.minimumLineSpacing = kScaleNum(1);
        flowLayout.footerReferenceSize = CGSizeMake(kScreenWidth, kScaleNum(108));
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, kScaleNum(46), kScreenWidth, kScreenHeight - kScaleNum(StatusHeight + 106)) collectionViewLayout:flowLayout];
        _collectionView.backgroundColor = kBgColor;
        _collectionView.dataSource = self;
        _collectionView.delegate = self;
        _collectionView.pagingEnabled = YES;
        _collectionView.showsVerticalScrollIndicator = NO;
        _collectionView.showsHorizontalScrollIndicator = NO;
        _collectionView.bounces = NO;
        [_collectionView registerClass:[SAPaperSetCollectionViewCell class] forCellWithReuseIdentifier:@"SAPaperSetCollectionViewCell"];
        [_collectionView registerClass:[SAPaperSetCollectionFootView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"SAPaperSetCollectionFootView"];
    }
    return _collectionView;
}

-(NSMutableArray<SAPaperSetModel *> *)dataMarr {
    if (!_dataMarr) {
        _dataMarr = [NSMutableArray array];
    }
    return _dataMarr;
}

-(NSMutableArray<SAPaperSetModel *> *)dataMarr2 {
    if (!_dataMarr2) {
        _dataMarr2 = [NSMutableArray array];
    }
    return _dataMarr2;
}

-(NSMutableArray<SAPaperSetModel *> *)laberMarr {
    if (!_laberMarr) {
        _laberMarr = [NSMutableArray array];
    }
    return _laberMarr;
}

-(NSDictionary *)dic {
    if (!_dic) {
        _dic = @{@"0":@"店铺", @"1":@"款号", @"2":@"名称", @"3":@"颜色", @"4":@"尺码", @"5":@"零售价", @"6":@"折扣价", @"7":@"成分含量", @"8":@"产品标准", @"9":@"安全类别", @"10":@"质量等级", @"11":@"洗涤方式", @"12":@"条码", @"13":@"品牌",@"14":@"显示特价",@"15":@"会员价",@"16":@"场地",@"17":@"经销商"};
    }
    return _dic;
}

-(NSMutableArray *)typeMarr {
    if (!_typeMarr) {
        _typeMarr = [NSMutableArray arrayWithObjects:@"40*30mm",@"40*60mm", @"40*80mm", @"30*20mm", @"60*40mm", nil];
    }
    return _typeMarr;
}

// 生成条形码
- (UIImage *)resizeCodeWithString:(NSString *)text BCSize:(CGSize)size
{
    CIImage *image = [self generateBarCodeImage:text];
    
    return [self resizeCodeImage:image withSize:size];
}

- (CIImage *)generateBarCodeImage:(NSString *)source
{
    // iOS 8.0以上的系统才支持条形码的生成，iOS8.0以下使用第三方控件生成
    if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
        // 注意生成条形码的编码方式
        NSData *data = [source dataUsingEncoding: NSASCIIStringEncoding];
        CIFilter *filter = [CIFilter filterWithName:@"CICode128BarcodeGenerator"];
        [filter setValue:data forKey:@"inputMessage"];
        // 设置生成的条形码的上，下，左，右的margins的值
        [filter setValue:[NSNumber numberWithInteger:0] forKey:@"inputQuietSpace"];
        return filter.outputImage;
    }else{
        return nil;
    }
}

- (UIImage *)resizeCodeImage:(CIImage *)image withSize:(CGSize)size
{
    if (image) {
        CGRect extent = CGRectIntegral(image.extent);
        CGFloat scaleWidth = size.width/CGRectGetWidth(extent);
        CGFloat scaleHeight = size.height/CGRectGetHeight(extent);
        size_t width = CGRectGetWidth(extent) * scaleWidth;
        size_t height = CGRectGetHeight(extent) * scaleHeight;
        CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceGray();
        CGContextRef contentRef = CGBitmapContextCreate(nil, width, height, 8, 0, colorSpaceRef, (CGBitmapInfo)kCGImageAlphaNone);
        CIContext *context = [CIContext contextWithOptions:nil];
        CGImageRef imageRef = [context createCGImage:image fromRect:extent];
        CGContextSetInterpolationQuality(contentRef, kCGInterpolationNone);
        CGContextScaleCTM(contentRef, scaleWidth, scaleHeight);
        CGContextDrawImage(contentRef, extent, imageRef);
        CGImageRef imageRefResized = CGBitmapContextCreateImage(contentRef);
        UIImage *barImage = [UIImage imageWithCGImage:imageRefResized];
        
        //Core Foundation 框架下内存泄露问题。
        CGContextRelease(contentRef);
        CGColorSpaceRelease(colorSpaceRef);
        CGImageRelease(imageRef);
        CGImageRelease(imageRefResized);
        return barImage;
    }else{
        return nil;
    }
}

- (UIImage*)createCodeWithString:(NSString*)str
                            size:(CGSize)size
                      CodeFomart:(ZXBarcodeFormat)format
{
    ZXMultiFormatWriter *writer = [[ZXMultiFormatWriter alloc] init];
    ZXBitMatrix *result = [writer encode:str format:format width:size.width height:size.width error:nil];
    ZXImage *image = [ZXImage imageWithMatrix:result];
    return [UIImage imageWithCGImage:image.cgimage];
}

@end
